using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class DisplayAllPoints : GenericDialog
{
	public Button button;

	public Image background;

	public Text label;

	[Space(10f)]
	public Image icon;

	[Space(10f)]
	public int value = 888;

	private int displayedValue = -1;

	private bool syncWithEconomy = true;

	[Space(10f)]
	public AnimationResourceFlow animationFlow;

	public Ease animationEase = Ease.Linear;

	public float animationInitialDelay = 0.4f;

	public float animationMoveDuration = 0.2f;

	public float animationInterval = 0.07f;

	public float animationValueDuration = 0.25f;

	public override void Start()
	{
		base.Start();
		if (syncWithEconomy && Economy.hasInstance)
		{
			value = Economy.totalPoints;
		}
		displayedValue = value;
		label.text = displayedValue.ToString();
	}

	private void Update()
	{
		TryUpdateDisplayValue();
	}

	private void TryUpdateDisplayValue()
	{
		if (displayedValue != value)
		{
			displayedValue = value;
			label.text = displayedValue.ToString();
			DoAnimationPulseScale(label, 1.5f, 1f, animationValueDuration);
		}
	}

	public void SetSyncWithEconomy(bool state)
	{
		syncWithEconomy = state;
		if (syncWithEconomy)
		{
			value = Economy.totalPoints;
		}
	}

	public void SyncWithEconomyOnce()
	{
		value = Economy.totalPoints;
	}

	public void Add(int howMany)
	{
		value += howMany;
	}

	public float AddAnimated(int howMany, RectTransform from = null, float flowSize = 60f, bool syncAfter = false)
	{
		bool flag = false;
		bool flag2 = false;
		if (from != null)
		{
			flag = true;
			flag2 = true;
			animationFlow.animationEase = animationEase;
			animationFlow.animationInitialDelay = animationInitialDelay;
			animationFlow.animationMoveDuration = animationMoveDuration;
			animationFlow.animationInterval = animationInterval;
			AudioClip clip = null;
			if ((bool)Audio.GetInstance())
			{
				clip = Audio.GetInstance().soundPoint;
			}
			animationFlow.Show(SpriteManager.GetInstance().spriteIconPoint, from, icon.rectTransform, howMany, flowSize, clip, 1f);
		}
		Sequence sequence = DOTween.Sequence();
		float num = 0f;
		if (flag)
		{
			num += animationInitialDelay;
		}
		if (flag2)
		{
			num += animationMoveDuration;
		}
		if (num > 0f)
		{
			sequence.AppendInterval(num);
		}
		int initialDisplayValue = value;
		float num2 = (float)Mathf.Clamp(howMany, 0, 10) * animationInterval - animationInterval;
		sequence.Append(DOTween.To(UpdateValue, initialDisplayValue, initialDisplayValue + howMany, num2));
		sequence.AppendCallback(delegate
		{
			UpdateValue(initialDisplayValue + howMany);
		});
		if (syncAfter)
		{
			sequence.AppendInterval(0.05f);
			sequence.AppendCallback(delegate
			{
				UserInterface.GetInstance().SyncDisplays();
			});
		}
		sequence.Play();
		float num3 = num2;
		if (flag)
		{
			num3 += animationInitialDelay;
		}
		if (flag2)
		{
			num3 += animationMoveDuration;
		}
		return num3;
	}

	private void UpdateValue(float newValue)
	{
		value = Mathf.RoundToInt(newValue);
		TryUpdateDisplayValue();
	}
}
